package Medium.Greedy;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author: white-zhou
 * @date: 2024-09-21 19:02
 **/
public class MaxArea {
    // 暴力解法
    public int maxArea(int[] height) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < height.length; i++) {
            for (int j = i + 1; j < height.length; j++) {
                int max = Math.min(height[i], height[j]) * (j - i);
                list.add(max);
            }
        }
        return Collections.max(list);
    }

    // 双指针
    public int maxArea1(int[] height) {
        int max = 0;
        int left = 0;
        int right = height.length - 1;
        while (left < right) {
            int area = Math.min(height[left], height[right]) * (right - left);
            max = Math.max(max, area);
            if (height[left] < height[right]) {
                left++;
            } else {
                right--;
            }
        }
        return max;
    }
}
